package ControlLayer;

import ModelLayer.*;
import java.util.ArrayList;
//model layer package has to be imported

/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{

    //declare instance variables to reference containers
    private AddressBook perContainer;

    public AddressCtr()
    {
        perContainer = AddressBook.getInstance();

    }

    /**
     *  Searches the container for a person with specified id
     *  @param id id to search for
     *  @return the person with the ID, or null if not found.
     *  KNP
     **/
    public Person findPerson(long id)
    {
        return perContainer.getPerson(id);  
    }

    public void createPerson(long id, String name, String address, String postalCode, String city, String phone)
    {   
        //creates a Person object and stores it in the container
        Person p = new Person(id, name, address, postalCode, city, phone);
        perContainer.addPerson(p);
    }

    public void deletePerson(long id)
    {
        //search for the person and delete the object from the container
        perContainer.deletePerson(id);
    }

    public void updatePerson(long id, String name, String address, String postalCode, String city, String phone)
    {
        Person p = findPerson(id);       

        p.setName(name);
        p.setAddress(address);
        p.setPostalCode(postalCode);
        p.setCity(city);
        p.setPhone(phone); 
    }

    public void listAllPersons()
    {
        perContainer.listAllPersons();        
    }
}
